const Router = require('koa-router');
const router = new Router();
const {db, Op} = require("../../models/db");
// 删除用户
// 删除用户
router.post('/cars/del', async ctx => {
    try {
        let user = ctx.user
        let body = ctx.request.body
        let tenantId = user.tenantId;
        let id = body.id
        let c = await db.models['cargo'].count({
            where: {
                tenantId,
                carsId: id
            }
        })
        if(c > 0) {
           let model =  await db.models['cars'].findOne({
               where: {
                   tenantId,
                   carsId: id
               }
           })
            model.isDel = 1
            await model.save()
        }
        else {
            await db.models['cars'].destroy({
                where: {
                    tenantId,
                    id
                }
            })
        }
        return ctx.suc('已删除');
    } catch (e) {
        return ctx.err(e)
    }
})

module.exports = router;
